package com.jiuyuan.exception;

import com.jiuyuan.entity.vo.RespBean;
import com.jiuyuan.entity.vo.RespBeanEnum;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.sql.SQLException;
import java.sql.SQLIntegrityConstraintViolationException;

/**
 * @program: hrms
 * @description:
 * @author: Feng
 * @create: 2023-02-16 15:40
 **/

@RestControllerAdvice
public class GlobalException {
    @ExceptionHandler(Exception.class)
    public RespBean ExceptionHandler(Exception e){
        if(e instanceof SQLIntegrityConstraintViolationException)
            return RespBean.error(RespBeanEnum.DELETE_HAVE_FOR_FILED);
        if(e instanceof SQLException)
            return RespBean.error("数据库出错");
        return RespBean.error(e.getMessage());
    }

}
